#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    bool backspaceCompare(string s, string t)
    {
        string str1, str2;
        for (auto ch : s)
        {

            if (!str1.empty() && ch == '#')
                str1.pop_back();
            if (ch != '#')
                str1.push_back(ch);
        }
        for (auto ch : t)
        {

            if (!str2.empty() && ch == '#')
                str2.pop_back();
            if (ch != '#')
                str2.push_back(ch);
        }
        if (str1.size() != str2.size()) return false;
        else
        {
            for (int i = 0; i < str1.size(); i++)
            {
                if (str1[i] != str2[i]) return false;
            }
        }
        return true;

    }
};